<?php

/**
 * @package Skjb_Library
 */

/**
 * Mencoder Tool
 *
 * @package Skjb_Library
 */
class Skjb_Video_Mencoder
{
    public $path = null;
    
    public $input = null;
    
    public $output = null;
    
    public $audioCodec = null;

    public $audioFile = null;

    public $videoCodec = null;

    public $vfwOptions = null;

    public $flip = false;

    public $outputFilter = null;

    public $videoFilter = null;

    public $maximumCorrection = null;
    
    public $lastCommand = null;

    public function __construct($path)
    {
        $this->path = $path;
    }
    
    public function reset()
    {
        $this->audioCodec = null;
        $this->audioFile = null;
        $this->videoCodec = null;
        $this->vfwOptions = null;
        $this->flip = false;
        $this->outputFilter = null;
        $this->videoFilter = null;
        $this->maximumCorrection = null;
    }
    
    public function run()
    {
        $command = $this->path;
        $command .= ' ' . $this->input;
        $command .= ' -o ' . $this->output;
        if ($this->audioCodec !== null) {
            $command .= ' -oac ' . $this->audioCodec;
        }
        if ($this->audioFile !== null) {
            $command .= ' -audiofile ' . $this->audioFile;
        }
        if ($this->videoCodec !== null) {
            $command .= ' -ovc ' . $this->videoCodec;
        }
        if ($this->vfwOptions !== null) {
            $command .= ' -xvfwopts ' . $this->vfwOptions;
        }
        if ($this->flip) {
            $command .= ' -flip';
        }
        if ($this->outputFilter !== null) {
            $command .= ' -of ' . $this->outputFilter;
        }
        if ($this->videoFilter !== null) {
            $command .= ' -vf ' . $this->videoFilter;
        }
        if ($this->maximumCorrection !== null) {
            $command .= ' -mc ' . $this->maximumCorrection;
        }
        $this->lastCommand = $command;
        $result = shell_exec($command);
        return $result;
    }
}